package com.xiaoyang.friend.controller.user;

import com.xiaoyang.common.core.constants.HttpConstants;
import com.xiaoyang.common.core.controller.BaseController;
import com.xiaoyang.common.core.domain.R;
import com.xiaoyang.common.core.domain.TableDataInfo;
import com.xiaoyang.friend.aspect.CheckUserStatus;
import com.xiaoyang.friend.domain.exam.dto.ExamDTO;
import com.xiaoyang.friend.domain.exam.dto.ExamQueryDTO;
import com.xiaoyang.friend.service.user.IUserExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController()
@RequestMapping("/user/exam")
public class UserExamController extends BaseController {

    @Autowired
    private IUserExamService examService;

    /**
     * 报名竞赛
     * @param token
     * @param examDTO
     * @return
     */
    @CheckUserStatus
    @PostMapping("/enter")
    public R<Void> enter(@RequestHeader(HttpConstants.AUTHENTICATION) String token,
                   @RequestBody ExamDTO examDTO) {
        return toR(examService.enter(token, examDTO.getExamId()));
    }

    /**
     * 我的竞赛列表
     * @param examQueryDTO
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        return getDataTable(examService.list(examQueryDTO));
    }

    /**
     * 我的竞赛列表--redis版
     * @param examQueryDTO
     * @return
     */
    @GetMapping("/redis/list")
    public TableDataInfo redisList(ExamQueryDTO examQueryDTO) {
       return examService.redisList(examQueryDTO);
    }
}
